const express = require("express")
const router = express.Router()
const { TechnicalDirection  } = require("../models")


router.get('/', async function(req, res) {  
    try {  
        const directions = await TechnicalDirection.findAll(); // 从模型中获取数据 
        // console.log(directions) 
        
        res.json({
          msg:"查询成功",
          result:directions
        }); // 返回 JSON 格式的结果  
    } catch (error) {  
        console.error('获取技术方向时出错:', error);  
        res.status(500).json({ error: '内部服务器错误' });  
    }  
});  


// router.get('/:id', async (req, res) => {
//     try {
//       const technicalDirection = await TechnicalDirection.findByPk(req.params.id);
//       if (!technicalDirection) {
//         return res.status(404).json({ message: 'Technical direction not found' });
//       }
//       res.status(200).json(technicalDirection);
//     } catch (err) {
//       res.status(500).json({ message: err.message });
//     }
//   }
// )

// router.post('/create',async (req, res) => {
//     try {
//       const userId = req.userId; // Assuming you have middleware to set this
//       const {
//         project_type,
//         title,
//         description,
//         technical_requirements,
//         budget_range_min,
//         budget_range_max,
//         expected_delivery_date
//       } = req.body;
  
//       const newProject = await Project.create({
//         project_type,
//         title,
//         description,
//         technical_requirements,
//         budget_range_min,
//         budget_range_max,
//         expected_delivery_date,
//         created_by_user_id: userId
//       });
  
//       res.status(201).json({
//         id: newProject.id,
//         status: 'created',
//         message: '项目已成功创建'
//       });
//     } catch (err) {
//       res.status(500).json({ message: err.message });
//     }})
// // 需要改
//     router.get('/update/:id',async (req, res) => {
//   try {
//     const projectId = req.params.projectId;
//     const { amounts, currencies, notes } = req.body;

//     if (!amounts || !currencies || amounts.length !== currencies.length) {
//       return res.status(400).json({ message: 'Invalid quote data' });
//     }

//     const quotesData = amounts.map((amount, index) => ({
//       project_id: projectId,
//       amount,
//       currency: currencies[index],
//       notes: notes ? notes[index] : null
//     }));

//     const generatedQuotes = await Quote.bulkCreate(quotesData);

//     res.status(201).json(generatedQuotes);
//   } catch (err) {
//     res.status(500).json({ message: err.message });
//   }
//   })

module.exports = router